/**
 * 
 */
package com.jm.web.builder.form;

import java.io.IOException;

import com.jm.utils.StringBuilderEx;
import com.jm.utils.StringHelper;
import com.jm.web.builder.BaseBuilder;

/**
 * @author yanjie
 * Jan 31, 2012 3:26:18 PM
 */
public class ButtonBuilder extends BaseBuilder{
	@Override
	public void RenderStart() {
		try {
			StringBuilderEx sb = new StringBuilderEx();
			sb.Append("<button type=\"button\" class=\"btn\" onmouseover=\"$(this).addClass('ax-btn-over');\" onmouseout=\"$(this).removeClass('ax-btn-over');\" onmousedown=\"$(this).addClass('ax-btn-pressed');\" onmouseup=\"$(this).removeClass('ax-btn-pressed');\" ");
			
			if(!StringHelper.IsNullOrEmpty(this.getBaseTag().getId()))
				sb.Append(" id=\"%1$s\"",this.getBaseTag().getId());
			
			if(this.getBaseTag().IsContainsKey("name"))
				sb.Append(" name=\"%1$s\"",this.getBaseTag().GetExtValue("name"));
			
			if(this.getBaseTag().IsContainsKey("style"))
				sb.Append(" style=\"%1$s\"",this.getBaseTag().GetExtValue("style"));
			
			if(this.getBaseTag().IsContainsKey("onclick"))
				sb.Append(" onclick=\"%1$s;return false;\"",this.getBaseTag().GetExtValue("onclick"));
			
			if(this.getBaseTag().IsContainsKey("disabled") && this.getBaseTag().GetExtValue("disabled", false))
				sb.Append(" disabled=\"%1$s\"",this.getBaseTag().GetExtValue("disabled"));
			
			sb.Append(">");
			
			sb.Append("<div class=\"%1$s %2$s\" style=\"vertical-align: middle;\">%3$s</div>",
					StringHelper.IsNullOrEmpty(this.getBaseTag().GetExtValue("icon","")) ? "btn-inner-nopadding" : "btn-inner",
					this.getBaseTag().GetExtValue("icon"),
					this.getBaseTag().GetExtValue("value"));
			
			this.getOut().write(sb.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	@Override
	public void RenderEnd() {
		try {
			this.getOut().write("</button>");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
